
var Watrix_Ajax = new Object();

function createAjaxObj() {
	var httprequest=false;
	if ( window.XMLHttpRequest ) {
		httprequest = new XMLHttpRequest();
		if ( httprequest.overrideMimeType ) {
			httprequest.overrideMimeType('text/xml');
		}
	} else if ( window.ActiveXObject ){
		try {
			httprequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e){
			try{
				httprequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e){}
		}
	}
	return httprequest;
}

function encodeURIString(f1, f2) {
    var _elements = eval(f1 +".document."+ f2 +".elements");
    var _array_elements = new Array(_elements.length);
    for( var ii=0; ii<_elements.length; ii++) {
        var element = eval("_elements["+ ii + "]");
        if ( ii==0 ) {
            //_array_elements[ii] = element.name + "=" + encodeURI(element.value);
			switch ( element.type) {
				case "checkbox":
					if ( element.checked ) {
						_array_elements[ii] = element.name + "=" + encodeURIComponent(element.value);
					}
					break;
				case "radio":
					if ( element.checked ) {
						_array_elements[ii] = element.name + "=" + encodeURIComponent(element.value);
					}
					break;
				default:
					_array_elements[ii] = element.name + "=" + encodeURIComponent(element.value);
			}
        } else {
            //_array_elements[ii] = "&" + element.name + "=" + encodeURI(element.value);
			switch ( element.type) {
				case "checkbox":
					if ( element.checked ) {
						_array_elements[ii] = "&" + element.name + "=" + encodeURIComponent(element.value);
					}
					break;
				case "radio":
					if ( element.checked ) {
						_array_elements[ii] = "&" + element.name + "=" + encodeURIComponent(element.value);
					}
					break;
				default:
					_array_elements[ii] = "&" + element.name + "=" + encodeURIComponent(element.value);
			}

        }
    }
    return _array_elements.join("");
}

Watrix_Ajax.basedomain      = "http://" + window.location.hostname;
Watrix_Ajax.ajaxobj         = createAjaxObj();
Watrix_Ajax.filetype        = "txt";
Watrix_Ajax.containerid = "contentarea";
Watrix_Ajax.addrandomnumber = 0;
Watrix_Ajax.getAjaxRequest  = function(url, parameters, callbackfunc, filetype) {
	Watrix_Ajax.ajaxobj = createAjaxObj();
	if ( Watrix_Ajax.addrandomnumber==1 ) {
		var parameters=parameters+"&ajaxcachebust="+new Date().getTime();
	}
	if ( this.ajaxobj ) {
		if ( isElementsType(filetype) ) { this.filetype = filetype; }
		this.ajaxobj.onreadystatechange=callbackfunc;
		this.ajaxobj.open('GET', url + "?" + parameters, true);
		this.ajaxobj.send(null);
	}
}

Watrix_Ajax.postAjaxRequest = function(url, parameters, callbackfunc, filetype) {
	try {
		Watrix_Ajax.ajaxobj = createAjaxObj();
		if ( this.ajaxobj ){
			if ( isElementsType(filetype) ) { this.filetype = filetype; }
			this.ajaxobj.onreadystatechange = callbackfunc;
			this.ajaxobj.open('POST', url, true);
			this.ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			this.ajaxobj.setRequestHeader("Content-length", parameters.length);
			this.ajaxobj.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate"); 
			this.ajaxobj.setRequestHeader("Pragma", "no-cache");
			//this.ajaxobj.setRequestHeader("Connection", "close");
			this.ajaxobj.send(parameters);
		}
	} catch(e) {
		alert(e);
	}
}

Watrix_Ajax.pageAjaxRequest = function(url, parameters, callbackfunc, containerid) {
	Watrix_Ajax.ajaxobj = createAjaxObj();
	if ( this.ajaxobj ){
		if ( isElementsType(containerid) ) { this.containerid = containerid; }
		this.ajaxobj.onreadystatechange = callbackfunc;
		this.ajaxobj.open('GET', url + "?" + parameters, true);
		this.ajaxobj.send(null);
	}
}
